package com.hongye.broker.controller;

import com.hongye.broker.service.MessageService;
import com.hongye.common.exception.ServiceException;
import com.hongye.common.response.ResponseResult;
import jodd.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/message")
public class MessageController {
    @Autowired
    private MessageService messageService;

    /*
    *消息列表
    */
    @RequestMapping("/list")
    public ResponseResult list(@RequestParam int brokerId){
        ResponseResult responseResult = messageService.list(brokerId);
        return responseResult;
    }


    /*
    * 删除
    * */
    @RequestMapping("/delete")
    public ResponseResult delete(@RequestParam int messageId){
        if (StringUtil.isEmpty(String.valueOf(messageId))){
            throw new ServiceException("401","参数为空");
        }

        ResponseResult responseResult = messageService.delete(messageId);
        return responseResult;
    }

    /*
    * 顶置
    * */
    @RequestMapping("/update")
    public ResponseResult update(@RequestParam int messageId){
        if (StringUtil.isEmpty(String.valueOf(messageId))){
            throw new ServiceException("401","参数为空");
        }

        ResponseResult responseResult = messageService.update(messageId);
        return responseResult;
    }
}
